//
//  MainTabBarController.swift
//  微博swift
//
//  Created by CrateMac0 on 16/3/20.
//  Copyright © 2016年 Users. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.setValue(AddTabbarView(), forKey: "tabBar")
        
        setVCAndAdd()
    }
    func setVCAndAdd(){
        let homeVC = HomeController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        
        let messageVC = MessageController()
        addChildViewController(messageVC, title: "信息", imageName: "tabbar_message_center")
        
        let discoverVC = DiscoverController()
        addChildViewController(discoverVC, title: "发现", imageName: "tabbar_discover")
        
        let profileVC = ProfileController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
    }
    func addChildViewController(controller: UIViewController, title: String, imageName: String) {
        
        controller.title = title
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        let imgNameH = imageName + "_highlighted"
        controller.tabBarItem.image = UIImage(named: imageName)
        controller.tabBarItem.selectedImage = UIImage(named: imgNameH)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        addChildViewController(UINavigationController(rootViewController: controller))
    } 

}
